<?php
/**
* 优惠券模块Api Controller
*
* 优惠券模块Api Controller的注意及说明
* 以下use模块请不要互相伤害
*
* @author    xiecz <xiecz@yunys.com.cn>
* @copyright 2016 QuanZhouYunYiShang Inc.
*/
namespace App\Http\Controllers\Api\Coupons;

use Illuminate\Routing\Controller as BaseController;
use Request, Response, DB;
use App\Services\Coupons\CouponsService;
use Endroid\QrCode\QrCode;

class CouponsController extends BaseController{

	function __construct(CouponsService $couponsS){
		$this->couponsS	= $couponsS;
		$this->middleware('transaction',['only'=>['postUserUnionCoupons']]);
	}

	//购物车用优惠券列表
	function postShopCarCoupons(){
		$input	= Request::all();
		$result = $this->couponsS->shopCarCoupons($input);
		return response()->json($result);
	}

	//用户中心优惠券列表√
	function postMyCoupons(){
		$input	= Request::all();
		$result	= $this->couponsS->myCoupons($input);
		return response()->json($result);
	}

	//立即购买用优惠券列表
	function buyImmediatelyCoupons(){
		$input	= Request::all();
		$result	= $this->couponsS->buyImmediatelyCoupons($input);
		return response()->json($result);
	}

	//用户优惠券绑定√
	function postUserUnionCoupons(){
		$input	= Request::all();
		$result	= $this->couponsS->userUnionCoupons($input);
		return response()->json($result);
	}

	//优惠券校验
	function postScanCoupon(){
		$input	= Request::all();
		$result = $this->couponsS->scanCoupon($input);
		return response()->json($result);
	}

	//二维码
	function getQrcode(){
		$input	= Request::all();
		$input['body'] = empty($input['body'])?'':$input['body'];
		$size	= 300;
		$qrCode = new QrCode();
		$qrCode->setText($input['body']);
		$qrCode->setSize($size);
		$qrCode->setPadding(10);
		$response = Response::make($qrCode->get(), 200);

		$response->header('content-type', 'image/png');
	//	return $response;
	//	dd($body);

		return $response;
	}

	//优惠券奖池发券
	function coupon_pool_from_active(){
		$input	= Request::all();
		$result = $this->couponsS->coupon_pool_from_active($input);
		return response()->json($result);
	}

	function test(){
		//$img = file_get_contents('http://mytee2.apiyys.com/api/coupon/qrcode?body={ "coupon_id": "119512U2H4O9",  "price": "1.00" }');
		//	   file_put_contents(public_path().'/images/coupon/1.png',$img);
		$input = Request::all();
		dd($input);
		return 'yes';
	}
}
